package com.zyz.I_多线程.常用方法;

/**
 * @author: vick
 * @Date: 2025/3/22
 * @Description:
 * @version: 1.0
 */
public class StopThread implements Runnable{

    private boolean flag = true;

    @Override
    public void run() {
        while (flag) {
            System.out.println(Thread.currentThread().getName() + "aaaa");
        }
    }

    public void stop() {
        flag = false;
    }

    public static void main(String[] args) throws InterruptedException {
        StopThread stopThread = new StopThread();
        new Thread(stopThread,"子线程1").start();

        for (int i = 0; i < 100; i++) {
            Thread.sleep(10);
            System.out.println(i);
            if (i == 90) {
                stopThread.stop();
                System.out.println("子线程1停止了");
            }
        }
    }
}
